package com.zhm.demo.nats;

//import de.javawi.jstun.attribute.ChangeRequest;
//import de.javawi.jstun.header.MessageHeader;
//import de.javawi.jstun.util.Utility;
//import java.net.*;
//
//public class JStunExample {
//    public static void main(String[] args) throws Exception {
//        MessageHeader sendMH = new MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
//        sendMH.generateTransactionID();
//
//        // 创建 ChangeRequest 属性（可选）
//        ChangeRequest changeRequest = new ChangeRequest();
//        sendMH.addMessageAttribute(changeRequest);
//
//        // 发送请求
//        DatagramSocket socket = new DatagramSocket();
//        InetAddress stunServer = InetAddress.getByName("stun.l.google.com");
//        DatagramPacket packet = new DatagramPacket(sendMH.getBytes(), sendMH.getBytes().length, stunServer, 19302);
//        socket.send(packet);
//
//        // 接收响应
//        byte[] buffer = new byte[512];
//        DatagramPacket response = new DatagramPacket(buffer, buffer.length);
//        socket.receive(response);
//
//        // 解析响应
//        MessageHeader receiveMH = new MessageHeader();
//        receiveMH.parseAttributes(buffer);
//        String publicIP = Utility.inetAddressToString(receiveMH.getMappedAddress().getAddress());
//        int publicPort = receiveMH.getMappedAddress().getPort();
//        System.out.println("公网地址: " + publicIP + ":" + publicPort);
//    }
//}